package com.ruoyi.web.controller.admin;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.BdmCloudInventory;
import com.ruoyi.system.domain.dto.BdmCloudInventoryDto;
import com.ruoyi.system.domain.dto.BdmCloudInventoryEditDto;
import com.ruoyi.system.domain.dto.CloudInventoryDetailDto;
import com.ruoyi.system.domain.vo.AgencyInventoryVo;
import com.ruoyi.system.domain.vo.BdmCloudInventoryItemVo;
import com.ruoyi.system.service.IBdmCloudInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 后台云库存
 * 
 * @author ruoyi
 * @date 2024-12-24
 */
@Validated
@RestController
@RequestMapping("/system/cloudInventory")
public class BdmCloudInventoryController extends BaseController
{
    @Autowired
    private IBdmCloudInventoryService bdmCloudInventoryService;

    /**
     * 查询代理库存列表
     *@return {@link AgencyInventoryVo}
     */
    @GetMapping("/listAgencyInventory")
    public TableDataInfo listAgencyInventory(BdmCloudInventoryDto bdmCloudInventoryDto)
    {
        startPage();
        List<AgencyInventoryVo> list = bdmCloudInventoryService.listAgencyInventory(bdmCloudInventoryDto);
        return getDataTable(list);
    }

    /**
     * 代理库存列表
     * @param dto
     * @return
     */
    @GetMapping("/listAgencyInventoryByUserId")
    public AjaxResult listAgencyInventoryByUserId(BdmCloudInventoryDto dto) {
        dto.setUserId(SecurityUtils.getUserId());
//        dto.setUserId(174541L);
        return bdmCloudInventoryService.listAgencyInventoryByUserId(dto);
    }

    /**
     * 查询代理库存详情
     * @return {@link BdmCloudInventory}
     */
    @GetMapping("/agencyInventory")
    public TableDataInfo listAgencyInventoryById(@NotNull(message = "用户编号必传")  Long userId)
    {
        startPage();
        List<BdmCloudInventory> list = bdmCloudInventoryService.listAgencyInventoryById(userId);
        return getDataTable(list);
    }


    /**
     * 后台 修改云库存
     */
    @PutMapping("modifiedInventory")
    public AjaxResult edit(@Valid @RequestBody BdmCloudInventoryEditDto bdmCloudInventoryEditDto)
    {
        return toAjax(bdmCloudInventoryService.modifiedInventory(bdmCloudInventoryEditDto));
    }

    /**
     *  后台查询云库存明细
     *  @return {@link BdmCloudInventoryItemVo}
     */
    @GetMapping("/cloudInventoryDetail")
    public TableDataInfo cloudInventoryDetail(CloudInventoryDetailDto cloudInventoryDetailDto)
    {
        startPage();
        List<BdmCloudInventoryItemVo> list = bdmCloudInventoryService.cloudInventoryDetail(cloudInventoryDetailDto);
        return getDataTable(list);
    }

    /**
     * 查询库存扣减类型
     */
    @GetMapping("/getInventoryDeductionType")
    public AjaxResult getInventoryDeductionType(){
       List<String> list= bdmCloudInventoryService.getInventoryDeductionType();
       return success(list);
    }


}
